<?php
/**
 * User: yujian
 * Date: 2018/11/30
 * Time: 13:19
 */

namespace app\tools;

use yii\base\Exception;
use yii\web\NotFoundHttpException;

class SocketHelper
{

    /**
     * websocket消息通信
     */
    public static function socket_message($push_data)
    {
        // 建立 连接到worker内部推送端口1001
        $client = stream_socket_client('tcp://127.0.0.1:9500', $errno, $errmsg, 1);
        //$client = stream_socket_client('tcp://47.96.82.77:9500', $errno, $errmsg, 1);
        // 推送的数据，包含uid字段，表示是给这个uid推送
        //$data = array('token' => $push_token, 'type' => $push_type, 'info' => $message);
        //var_dump(json_encode($data));die;
        fwrite($client, $push_data."\n");   
    }
}